package com.ymttest.database.sqlwapper.shenqisettlement;

import java.util.HashMap;
import java.util.List;

import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.shenqisettlement.OrderSettlement;
import com.ymttest.utils.YMTDateUtil;

public class OrderSettlementWrapper {

	SqlManager manager;

    public OrderSettlementWrapper() {
        manager = new SqlManager("shenqisettlement");
    }
    
    @SuppressWarnings("unchecked")
	public List<OrderSettlement> selectByPaymentId(long paymentId) {
    	
    	List<OrderSettlement> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.shenqisettlement.OrderSettlementMapper.selectByPaymentId",
                        paymentId);
        manager.commit();
        
		if (result.size() == 0) {
			Logger.comment("order_settlement没有数据");
		}
		
		return result;
    }
    
    @SuppressWarnings("unchecked")
	public OrderSettlement selectByPaymentIdAndOrderId(long paymentId, long orderId) {
    	
    	HashMap<String, Long> map = new HashMap<>();
    	
    	map.put("payment_id", paymentId);
    	map.put("order_id", orderId);
    	
    	List<OrderSettlement> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.shenqisettlement.OrderSettlementMapper.selectByPaymentIdAndOrderId",
                        map);
        manager.commit();
        
		if (result.size() == 0) {
			Logger.comment("order_settlement没有数据");
		}
		
		return result.get(0);
    }
    
    @SuppressWarnings("unchecked")
	public OrderSettlement selectByPrimaryKey(long orderId) {
    	
    	OrderSettlement orderSettlement = null;
    	
    	List<OrderSettlement> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.shenqisettlement.OrderSettlementMapper.selectByPrimaryKey",
                        orderId);
        manager.commit();
        
		if (result.size() == 0) {
			Logger.comment("order_settlement没有数据");
		}
		else 
			orderSettlement = result.get(0);
		
		return orderSettlement;
    }
    
    /**
     * 将未结算的结算单置为废弃
     */
    public void updateStatus() {
    	
    	YMTDateUtil.getBeforeOrNextDate(-1);
    	
    	manager.update("com.ymttest.database.mapping.shenqisettlement.OrderSettlementMapper.updateStatus",
    			YMTDateUtil.getBeforeOrNextDate(-1));
    	manager.commit();
    }
	
    public static void main(String[] args) {
    	
    	OrderSettlementWrapper test = new OrderSettlementWrapper();
//    	test.updateStatus();
    	System.out.println(test.selectByPaymentIdAndOrderId(1800042999, 1540032999).getBid_currency());
    }
}
